package com.dasel.math;

/**
 * Created by IntelliJ IDEA.
 * User: benoit
 * Date: 03-Mar-2010
 * Time: 01:34:42
 * To change this template use File | Settings | File Templates.
 */

import java.lang.*;
import java.util.*;

public class Jrid {
    private Integer rows;
    private Integer cols;
    private double[][] matrix;

    public Jrid(double[][] matrix, Integer rows, Integer cols) {
        this.matrix = matrix;
        this.rows = rows;
        this.cols = cols;
    }

    public Jrid plus(Jrid right) {
        if (rows != right.rows) throw new RuntimeException("Matrix A and Matrix B must be same size");
        double[][] results = new double[rows][cols];
        for (int i = 0; i < rows; i++) {
            double[] a = this.matrix[i];
            double[] b = right.matrix[i];
            double[] r = results[i];
            for (int j = 0; j < cols; j++) {
                r[j] = a[j] + b[j];
            }
        }
        return new Jrid(results, rows, cols);
    }


    public Jrid plus(double right) {
        double[][] results = new double[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                results[i][j] = this.matrix[i][j] + right;
            }
        }
        return new Jrid(results, rows, cols);
    }

    public Jrid multiply(Jrid right) {
        if (rows != right.rows) throw new RuntimeException("Matrix A and Matrix B must be same size");
        double[][] results = new double[rows][cols];
        for (int i = 0; i < rows; i++) {
            double[] a = this.matrix[i];
            double[] b = right.matrix[i];
            double[] r = results[i];
            for (int j = 0; j < cols; j++) {
                r[j] = a[j] * b[j];
            }
        }
        return new Jrid(results, rows, cols);
    }


    public Jrid multiply(double right) {
        double[][] results = new double[rows][cols];
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                results[i][j] = this.matrix[i][j] * right;
            }
        }
        return new Jrid(results, rows, cols);
    }

}
